<template>
  <div class="student">
    <h1>{{ msg }}</h1>
    <h2>学生姓名：{{ name }}</h2>
    <h2>学生性别：{{ sex }}</h2>
    <h2>学生年龄：{{ age + 1 }}</h2>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
export default {
  name: "StudentlInfo",
  data() {
    return {
      msg: "毕业于临沂大学的学生",
      name: "大志强",
      sex: "男",
      age: 18,
    };
  },
  mounted() {
    this.id = pubsub.subscribe('hello',function(a,data){   //订阅消息
      console.log("有人发布了hello消息，消息的回调执行了消息内容",a,data)
    })
  },
  beforeDestroy(){
    pubsub.unsubscribe(this.id) //此处可以将返回的id传递给this，然后就能访问了 
  }
};
</script>
<style scoped>
.student {
  background-color: aqua;
}
</style>

